package org.noote.libs.widget;

import javax.microedition.khronos.opengles.GL10;
import org.noote.libs.font.GLText;
import android.content.Context;

public class WidgetTheme {
	
	public static int TEXTID_25P=0, TEXTID_PAD=1, TEXTID_LABEL=2, TEXTID_UDLR=3, TEXTID_VROT=4, TEXTID_ZOOM=5, TEXTID_CAROUSELITEM=6;
	WidgetTexturePack _textures = new WidgetTexturePack();
	
	public static int ICON_ON=0, ICON_OFF=1, ICON_SETTING=2, ICON_PLUS=3, ICON_HELP=4;
	WidgetTexturePack _icons = new WidgetTexturePack();
	
	GLText fontRegular12;
	GLText fontRegular16;
	
	//float colorTextDefault[] = {0.3f, 0.62f, 1, 1};
	float colorTextDefault[] = {0.4f, 0.8f, 1.0f, 1};
	float colorSkinDefault[] = {0.3f, 0.62f, 1, 1};
	float colorIconDefault[] = {1, 1, 1, 1};
	
	float colorTextSelected[] = {0.7f, 1, 0.7f, 1};
	float colorSkinSelected[] = {0.4f, 0.8f, 1.0f, 1};
	float colorIconSelected[] = {1, 1, 1, 1};
	
	float colorTextDisabled[] = {0.65f, 0.65f, 0.7f, 1};
	float colorSkinDisabled[] = {0.65f, 0.65f, 0.7f, 1};
	float colorIconDisabled[] = {0.65f, 0.65f, 0.7f, 1};
	
	public float colorWhite[] = {1.0f, 1.0f, 1.0f, 1};
	public float colorLightGray[] = {0.75f, 0.75f, 0.8f, 1};
	public float colorGray[] = {0.65f, 0.65f, 0.7f, 1};
	public float colorDarkGray[] = {0.5f, 0.5f, 0.55f, 1};
	
	int padSizeX = 128, padSizeY = 128;
	int iconSizeX = 64, iconSizeY = 64; 
	
	public void load(Context ctx, GL10 gl)
	{
		loadFonts(ctx, gl);
		loadIcons(ctx, gl);
		loadImages(ctx, gl);
	}
	
	public void drawText(GL10 gl, float x, float y, String sText, boolean bCentred)
	{
		drawText(gl, colorTextDefault, x, y, sText, bCentred);
	}
	public void drawText(GL10 gl, int c, float x, float y, String sText, boolean bCentred)
	{
		float cf[] = new float[4];
		cf[0] = ((c&0xff000000)>>24)/255.0f;
		cf[1] = ((c&0x00ff0000)>>16)/255.0f;
		cf[2] = ((c&0x0000ff00)>>8)/255.0f;
		cf[3] = (c&0x000000ff)/255.0f;
		drawText(gl, cf, x, y, sText, bCentred);
	}
	public void drawText(GL10 gl, float [] c, float x, float y, String sText, boolean bCentred)
	{
		gl.glDisable(GL10.GL_DEPTH_TEST);
		gl.glEnable( GL10.GL_TEXTURE_2D);
	    gl.glEnable( GL10.GL_BLEND );
	    gl.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
	      
		fontRegular16.begin(c[0], c[1], c[2], c[3]);
		if(bCentred)
			fontRegular16.drawC(sText, x, y);
		else
			fontRegular16.draw(sText, x, y);
		fontRegular16.end();
		
		gl.glDisable( GL10.GL_BLEND );
	    gl.glDisable( GL10.GL_TEXTURE_2D );
	    gl.glEnable(GL10.GL_DEPTH_TEST);
	}

	protected void loadFonts(Context ctx, GL10 gl) {
		fontRegular12 = new GLText( gl, ctx.getAssets() );
		fontRegular12.load( "Roboto-Regular.ttf", 12, 2, 2 );
		fontRegular16 = new GLText( gl, ctx.getAssets() );
		fontRegular16.load( "Roboto-Regular.ttf", 16, 3, 2 );
	}

	protected void loadImages(Context ctx, GL10 gl) {
		if(_textures.create(gl, 7))
		{
			_textures.loadImageFromResource(ctx, R.drawable.widget_128x128_25p, gl, TEXTID_25P);
			_textures.loadImageFromResource(ctx, R.drawable.widget_128x128_pad, gl, TEXTID_PAD);
			_textures.loadImageFromResource(ctx, R.drawable.widget_128x128_label, gl, TEXTID_LABEL);
			_textures.loadImageFromResource(ctx, R.drawable.widget_128x128_up_down_left_right, gl,TEXTID_UDLR);
			_textures.loadImageFromResource(ctx, R.drawable.widget_128x128_vertical_rotate, gl, TEXTID_VROT);
			_textures.loadImageFromResource(ctx, R.drawable.widget_128x128_zoom, gl, TEXTID_ZOOM);
			_textures.loadImageFromResource(ctx, R.drawable.widget_128x128_carousel_item, gl, TEXTID_CAROUSELITEM);
		}
	}
	protected void loadIcons(Context ctx, GL10 gl) {
		if(_icons.create(gl, 5))
		{
			_icons.loadImageFromResource(ctx, R.drawable.icon_64x64_on, gl, ICON_ON);
			_icons.loadImageFromResource(ctx, R.drawable.icon_64x64_off, gl, ICON_OFF);
			_icons.loadImageFromResource(ctx, R.drawable.icon_64x64_settings, gl, ICON_SETTING);
			_icons.loadImageFromResource(ctx, R.drawable.icon_64x64_plus, gl, ICON_PLUS);
			_icons.loadImageFromResource(ctx, R.drawable.icon_64x64_help, gl, ICON_HELP);
		}
	}

}
